// CVEJB.java
package cv;

import java.rmi.RemoteException;

import javax.ejb.CreateException;
import javax.ejb.EJBException;
import javax.ejb.EntityBean;
import javax.ejb.EntityContext;
import javax.ejb.RemoveException;
import javax.ejb.SessionContext;

import student.Student;
import descriptor.CVDescriptor;


/**
 * CVBean
 * 
 * @author Mamadou TOURE
 * 
 * The CVBean class implements all the methods that a remote client expect to find
 * when it calls the interface (CV).
 * 
 * Note : 	-It extends the EntityBean class.
 */
@SuppressWarnings("unchecked")
public  abstract class CVBean implements EntityBean 
{	
	// simple attributes
	/** 
	 * getId
	 * 
	 * The getId abstract method returns a integer which indicates identification number of a CV.
	 * 
	 * @return		The user identification number of a user.
	 */
	public abstract int getId();
	
	/** 
	 * setId
	 * 
	 * The setId abstract method sets the identification number of a CV.
	 * 
	 * @param id		The new CV's identification number that we want to add.
	 */
	public abstract void setId(int id);
	
	public abstract String getFileName();
	public abstract void setFileName(String filename);
	
	/** 
	 * getFilelocation
	 * 
	 * The getFilelocation abstract method returns a string which indicates the location of the CV on the server machine.
	 * 
	 * @return		The file location on the server.
	 */
	public abstract String getFilelocation();
	
	/** 
	 * setFilelocation
	 * 
	 * The setFilelocation abstract method sets the file location of the CV on the server.
	 * 
	 * @param fileLocation		The new file location on the server.
	 */
	public abstract void setFilelocation(String fileLocation);
	
	/** 
	 * getPublishAuth
	 * 
	 * The getPublishAuth abstract method returns a boolean which indicates if the student authorizes the others users to view his CV.
	 * 
	 * @return		An authorization to view the CV (true or false).
	 */
	public abstract boolean getPublishAuth();
	
	/** 
	 * setFilelocation
	 * 
	 * The setFilelocation abstract method sets the file location of the CV on the server.
	 * 
	 * @param fileLocation		The new file location on the server.
	 */
	public abstract void setPublishAuth(boolean auth);
	
	//bean attributes
	//relation 1-1
	/** 
	 * getStudent
	 * 
	 * The getStudent abstract method returns an object of type Student which provides the student's details,
	 * (eg. userID,......).
	 * 
	 * @return		A student's object.
	 */
	public abstract Student getStudent();
	
	/** 
	 * setStudent
	 * 
	 * The setStudent abstract method sets an object of type Student.
	 * 
	 * @param id		A new user's object..
	 */
	public abstract void setStudent(Student student);
	
	/** 
	 * ejbCreate
	 * 
	 * The ejbCreate method defines the operations to follow to create an EJB.
	 * This method refers to the method create in the remote interface.
	 * 
	 * @param fileLocation		CV's location file address.
	 * @param auth				CV's view authorization.
	 * @param student			CV's student owner.
	 * 
	 * @return 					Return's values is always null.
	 */
    public String ejbCreate(String fileName, String fileLocation, boolean auth, Student student) throws CreateException
    {  	
    	setFileName(fileName);
    	setFilelocation(fileLocation);
		setPublishAuth(auth);
		return null;
		
    }

    /** 
	 * ejbPostCreate
	 * 
	 * The ejbPostCreate method defines the operations to follow after creating an EJB.
	 * 
	 * @param fileLocation		CV's location file address.
	 * @param auth				CV's view authorization.
	 * @param student			CV's student owner.
	 * 
	 */
    public void ejbPostCreate(String fileName, String fileLocation, boolean auth, Student student) 
    {
    	setStudent(student);
    }
    
    /** 
	 * getDescriptor
	 * 
	 * The getDescriptor method provides a Java object instead of a bean object. Hence, the object is directly accessible from a servlet or a JSP. 
	 * 
	 * @param getId()					The ID of the CV
	 * @param getFilelocation()			The CV's location file string
	 * @param getPublishAuth()			The CV's publication authorisation
	 * @param getStudent()				The CV's student owner
	 * 
	 * @return 							A CV Descriptor's object.
	 */
	public CVDescriptor getDescriptor()
	{
		return new CVDescriptor(getId(),getFileName(),getFilelocation(),getPublishAuth(),getStudent().getId());
	}
   
    public void ejbActivate() throws EJBException, RemoteException {}
	public void ejbPassivate() throws EJBException, RemoteException {}
	public void ejbRemove() throws EJBException, RemoteException,RemoveException {}
	public void setSessionContext(SessionContext arg0) throws EJBException, RemoteException {}
	public void ejbLoad() throws EJBException, RemoteException {}
	public void ejbStore() throws EJBException, RemoteException {}
	public void setEntityContext(EntityContext arg0) throws EJBException, RemoteException {}
	public void unsetEntityContext() throws EJBException, RemoteException {}
}



